package com.bgs.engineering.security.commonhandler;

import com.bgs.engineering.common.errorCode.EmErrorCode;
import com.bgs.engineering.common.response.CommonResult;
import com.bgs.engineering.common.response.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * @ClassName AuthExceptionEntryPoint
 * @Description 自定登录失败做出的返回结果
 * @Author zcy
 * @Date 2023/3/27 11:14
 **/
@Component
public class AuthExceptionEntryPoint implements AuthenticationEntryPoint {
    /**
     * 返回错误结果
     * @param request
     * @param response
     * @param authException
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ResponseUtil.responseJson(response, CommonResult.error(EmErrorCode.USER_NOT_LOGIN));
    }
}
